11 const int MAXN
= 1000, MAXC
= 100;
16 edge(int I
, int G
, int W
) : i(I
), g(G
), w(W
) {}
17 bool operator < (const edge
&that
) const {
22 int p
[MAXN
], d
[MAXN
][MAXC
+1], n
, visited
, maxQSize
;
26 int dijkstra(const int &start
, const int &end
, const int &c
){
27 for (int i
=0; i
<n
; ++i
)
28 for (int j
=0; j
<=c
; ++j
)
31 priority_queue
<edge
> q
;
32 q
.push(edge(start
, 0, 0));
37 maxQSize
= max(maxQSize
, (int)q
.size());
42 //printf("popped <%d, %d, %d>\n", u.i, u.g, u.w);
46 if (d
[u
.i
][u
.g
] < u
.w
) continue;
50 vector
<edge
> &v
= g
[u
.i
];
51 for (int j
=0; j
<v
.size(); ++j
){
52 int distance
= v
[j
].w
;
53 int neighbor
= v
[j
].i
;
54 for (int k
= distance
- u
.g
; k
<= c
+ distance
- u
.g
; ++k
){
55 int new_gas
= u
.g
- distance
+ k
;
56 if (k
>= 0 && 0 <= new_gas
&& u
.g
+ k
<= c
){
57 int w_extra
= k
*p
[u
.i
];
58 //assert(w_extra >= 0);
59 if (u
.w
+ w_extra
< d
[neighbor
][new_gas
]){
60 d
[neighbor
][new_gas
] = u
.w
+ w_extra
;
61 q
.push(edge(neighbor
, new_gas
, u
.w
+ w_extra
));
62 //printf(" pushed <%d, %d, %d>\n", neighbor, new_gas, u.w + w_extra);
74 scanf("%d %d", &n
, &m
);
75 for (int i
=0; i
<n
; ++i
){
81 scanf("%d %d %d", &u
, &v
, &d
);
82 g
[u
].push_back(edge(v
, 0, d
));
83 g
[v
].push_back(edge(u
, 0, d
));
90 scanf("%d %d %d", &c
, &s
, &e
);
93 int t
= dijkstra(s
, e
, c
);
97 printf("impossible\n");
99 printf(" Visited %d states with maximum queue size of %d\n", visited
, maxQSize
);